bitkeeper revision 1.748 (403b97dbiFb-AZhRznWy1vCMR3qzKA)
authormwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Tue, 24 Feb 2004 18:28:43 +0000 (18:28 +0000)
committermwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Tue, 24 Feb 2004 18:28:43 +0000 (18:28 +0000)
xendomains Sys-V init script now supports LSB-compliant systems

tools/examples/xendomains

index 8133bdf7ab2ab938d2aaca2ef013736e37c3ad60..fa96ff8378374f3a931502479120261a704ad8de 100755 (executable)
@@ -6,7 +6,9 @@
 # chkconfig: 345 99 00
 # description: Start / stop Xen domains.
 #
-# This script offers fairly basic functionality.
+# This script offers fairly basic functionality.  It should work on Redhat
+# but also on LSB-compliant SuSE releases and on Debian with the LSB package
+# installed.  (LSB is the Linux Standard Base)
 #
 # Based on the example in the "Designing High Quality Integrated Linux
 # Applications HOWTO" by Avi Alkalay
 RETVAL=0
 
 INITD=/etc/init.d/
-. $INITD/functions
 
-on_fn_exit()
-{
-    if [ $RETVAL -eq 0 ]; then
-       success
-    else
-       failure
-    fi
-    
-    echo
-}
+if [ -e /lib/lsb ]; then
+    # assume an LSB-compliant distro (Debian with LSB package,
+    # recent-enough SuSE, others...)
+
+    . /lib/lsb/init-functions # source LSB standard functions
+
+    on_fn_exit()
+    {
+       if [ $RETVAL -eq 0 ]; then
+           log_success_msg
+       else
+           log_failure_msg
+       fi
+    }
+else
+    # assume a Redhat-like distro
+    . $INITD/functions # source Redhat functions
+
+    on_fn_exit()
+    {
+       if [ $RETVAL -eq 0 ]; then
+           success
+       else
+           failure
+       fi
+       
+       echo
+    }
+fi
+
+
 
 start() {
     if [ -f /var/lock/subsys/xendomains ]; then return; fi
@@ -36,7 +58,8 @@ start() {
 
     # we expect config scripts for auto starting domains to be in
     # /etc/xc/auto/ - they could just be symlinks to files elsewhere
-    if [ $(ls /etc/xc/auto/ | wc -l) -gt 0 ]; then
+    if [ -d /etc/xc/auto ] &&
+           [ $(ls /etc/xc/auto/ | wc -l) -gt 0 ]; then
        
        # create all domains with config files in /etc/xc/auto
        for dom in /etc/xc/auto/*; do
@@ -45,9 +68,9 @@ start() {
                RETVAL=$?
            fi
        done
-    fi
 
-    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/xendomains
+       touch /var/lock/subsys/xendomains
+    fi
 
     on_fn_exit
 }
@@ -61,7 +84,8 @@ stop()
     
     echo -n $"Shutting down all Xen domains:"
 
-    if [ $(ls /var/run/xendomains/ | wc -l) -gt 0 ]; then
+    if [ -d /var/run/xendomains ] &&
+           [ $(ls /var/run/xendomains/ | wc -l) -gt 0 ]; then
        
        cd /var/run/xendomains/